from django.db import models
from django.contrib.auth.models import User
from utils import choices
from book import models as models_book

# Create your models here.
class Account(models.Model):
    # 使用 django 默认 User 表作为验证基础
    # User 和 Account 为一对一关系
    # 也可采用继承 AbstractUser 的方式
    user = models.OneToOneField(
        User,
        unique=True,
        verbose_name='对应验证账号',
        on_delete=models.PROTECT,
    )

    #帐号
    username=models.CharField(
        verbose_name='帐号',
        max_length=100,
        unique=True,
        default=None
    )

    # 真实信息
    nickname = models.CharField(
        max_length=100,
        verbose_name='昵称',
        blank=True
    )

    country = models.CharField(
        max_length= 100,
        verbose_name='国家',
        blank=True,
    )

    province = models.CharField(
        max_length= 100,
        verbose_name='省份',
        blank=True,
    )

    city = models.CharField(
        max_length= 100,
        verbose_name='城市',
        blank=True,
    )

    language = models.CharField(
        max_length= 100,
        verbose_name='语言',
        blank=True,
        null=True,
    )

    gender = models.CharField(
        max_length= 20,
        verbose_name='性别',
        blank=True,
        null=True,
    )

    avatarUrl = models.URLField(
        verbose_name='头像',
        blank=True,
        null=True,
    )

    last_login = models.DateTimeField(
        verbose_name="最近一次登陆时间",
        auto_now=True,
        null=True,
    )

    university = models.CharField(
        max_length=100,
        verbose_name="用户所在大学",
        blank=True,
        null=True,

    )
    phone=models.CharField(
        max_length= 30,
        verbose_name='手机号',
        blank=True,
        null=True,
    )

class Logdata(models.Model):
    account_id = models.IntegerField(
        verbose_name='用户ID'
    )
    action_type=models.CharField(
        max_length=2,
        verbose_name="操作类型",
        choices=choices.ACTION_TYPE,
    )
    search_time = models.DateTimeField(
        verbose_name='搜题时间',
        auto_now_add=True,
    )
    book_id=models.IntegerField(
        verbose_name='图书ID',
        blank=True,
        null=True,
    )

    ti_id = models.IntegerField(
        verbose_name='题目ID',
        blank=True,
        null=True,
    )
    keyword=models.CharField(
        max_length=100,
        verbose_name="搜索关键字",
        blank=True,
        null=True,
    )



class AccountBook(models.Model):
    account_id = models.IntegerField(
        verbose_name='用户ID',
    )

    book_id=models.IntegerField(
        verbose_name='图书ID',
    )

    status = models.CharField(
        verbose_name="课本状态",
        max_length = 10,
        choices=choices.MY_BOOK_STATUS,
    )


class Advice(models.Model):
    account=models.ForeignKey(
        Account,
        verbose_name="账号",
        on_delete=models.PROTECT,
    )
    advice_type=models.CharField(
        max_length=2,
        verbose_name="建议类型",
        choices=choices.ADVICE_TYPE,
    )
    book_id = models.IntegerField(
        verbose_name='图书ID',
        blank=True,
        null=True,
    )
    ti_id = models.IntegerField(
        verbose_name='题目ID',
        blank=True,
        null=True,
    )
    content=models.CharField(
        max_length=200,
        blank=True,
        null=True,
    )
